package com.xl.staticword;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassDescription:
 * @JdkVersion: 1.8
 * @Author: lei·xie
 * @Created: 2024/3/15 0015 16:07
 */
public class Test {
    public static void main(String[] args) {
        Student.name = "袁华";

        Student s1 = new Student();
        s1.name = "马冬梅";

        Student s2 = new Student();
        s2.name = "秋雅";

        System.out.println(s1.name); //秋雅  因为name静态变量，只有一份，所以s1.name和s2.name都指向了同一个地址
        System.out.println(s2.name);

        int schoolStudentId = 4305819;
        String idNum = "35202168784305819";
        //int length = schoolStudentId+"".length();
        int length = String.valueOf(schoolStudentId).length();
        String newNum = idNum.substring(0,idNum.length()-length);
        System.out.println(newNum);


        List<Integer> examIdList = Arrays.asList(1, 2, 3, 2, 4, 3, 5, 6, 1);
        List<Integer> duplicateExamIds = collectDuplicateExamIds(examIdList);
        System.out.println(duplicateExamIds.contains(1));
        System.out.println(duplicateExamIds.contains(4));
        System.out.println(duplicateExamIds);

    }

    public static List<Integer> collectDuplicateExamIds(List<Integer> examIdList) {
        return examIdList.stream().filter(ExamId -> Collections.frequency(examIdList, ExamId) > 1).distinct()
                .collect(Collectors.toList());
    }
}
